//
//  YHYMViewViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/4/12.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "YHYMViewViewController.h"
#import "WSMineCell.h"
#import "WSMineHeaderView.h"
#import "WSMineFooterView.h"
#import "SheeViewController.h"
#import "VippViewController.h"
#import "VipViewController.h"
#import "SupeiViewController.h"
#import "qianViewController.h" //充值
#import "YHYDesigneViewsViewController.h"
#import "YHYEditHomePageViewController.h"//添加任务
#import "WUPriveViewController.h"
#import "WUTaskController.h"
#import "WUConnectViewController.h" //沟通过的人物
#import "WUStoreViewController.h"  //收藏过的任务
#import "WUShareSheet.h"//分享
#import "UIImage+BlurScreenImage.h"
#import "UIView+Screen.h"
#import "TLAdvertisementTableViewCell.h"

@interface YHYMViewViewController ()<UITableViewDataSource,UITableViewDelegate,WSMineFooterViewDelegate,WSMineHeaderViewDelegate,WUShareSheetDelegate>
{
    
    NSArray *adImageArray;
    NSArray *adTitleTextArray;
    
    
}

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) WSMineHeaderView *headView;
@property (nonatomic,strong) NSArray *titleArr;

@end

@implementation YHYMViewViewController

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar"] forBarMetrics:UIBarMetricsDefault];
//    self.navigationController.navigationBar.backgroundColor = HS;
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    //self.navigationController.navigationBarHidden = YES;
//    self.navigationController.navigationBar.alpha = 0;
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    adImageArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"watch.jpg"], nil];
    adTitleTextArray = [NSArray arrayWithObjects:@"腕表之家",nil];
    _titleArr=[NSArray arrayWithObjects:@"我的主页",@"我的钱包", nil];
    
    self.view.backgroundColor = LV;
    
    //分享
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigation_share@2p"] style:UIBarButtonItemStylePlain target:self action:@selector(shareAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    //设置
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigation_shezhi@2p"] style:UIBarButtonItemStylePlain target:self action:@selector(setAction)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49) style:UITableViewStylePlain];
    self.tableView.backgroundColor = LV;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 50 * AUTO_HEIGHT;
    self.tableView.showsVerticalScrollIndicator = NO;
    //去掉线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    // self.tableView.backgroundColor = LV;
    [self.view addSubview:_tableView];
    [self.tableView registerClass:[WSMineCell class] forCellReuseIdentifier:@"cell"];
    [self.tableView registerClass:[TLAdvertisementTableViewCell class] forCellReuseIdentifier:@"adCell"];
    //头视图
    self.headView = [[WSMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 360 * AUTO_HEIGHT)];
    self.headView.delegate = self;
    self.tableView.tableHeaderView = self.headView;
    
    
    //
    //    WSMineFooterView *footView = [[WSMineFooterView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260 * AUTO_WIDTH)];
    //    footView.delegate = self;
    //    self.tableView.tableFooterView = footView;
    
    
    
}
#pragma mark -- tableView delegate && dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 3) {
        return adImageArray.count;
    }
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 8 * AUTO_HEIGHT;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 2 || indexPath.section == 3) {
        return  200 *AUTO_WIDTH;
    }
    else {
        
        return 44 *AUTO_WIDTH;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WSMineCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (indexPath.section == 2) {
        WSMineFooterView *footView = [[WSMineFooterView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200 * AUTO_WIDTH)];
        footView.delegate = self;
        footView.backgroundColor = [UIColor whiteColor];
        [cell addSubview:footView];
    }
    if (indexPath.section == 0 || indexPath.section == 1) {
        
        cell.titleStr = _titleArr[indexPath.section];
        
        
    }
    if (indexPath.section == 3) {
        TLAdvertisementTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"adCell"];
        cell.adImageView.image = adImageArray[indexPath.row];
        cell.remarkLabel.text = adTitleTextArray[indexPath.row];
        return cell;
        
    }
    //    else {
    //        cell.titleStr = @"";
    //        cell.icoImage.image = nil;
    //
    //
    //    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WSMineCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selected = NO;
    
    
    if (indexPath.section == 0 ) {
        WUPriveViewController *edit=[[WUPriveViewController alloc]init];
        edit.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:edit animated:YES];
    }
    
    if (indexPath.section == 3) {
        NSLog(@"广告位哦");
    }
    
    else if (indexPath.section == 1)
    {
        
        qianViewController *qian=[[qianViewController alloc]init];
        [self.navigationController pushViewController:qian animated:YES];
    }
    
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.navigationController.navigationBar.alpha = scrollView.contentOffset.y/120.00*AUTO_HEIGHT;

     [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_background.png"] forBarMetrics:UIBarMetricsDefault];
    
     
    [self.headView updateHeaderView:scrollView.contentOffset];
    
}

#pragma mark -- headerView代理方法
- (void)pushDetailViewController:(NSInteger)type {
    
    
    switch (type) {
        case MINEHEADERSELECTWORK:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
                
                WUTaskController *edit=[[WUTaskController alloc]init];
                edit.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:edit animated:YES];
            }
            break;
            
        case MINEHEADERSELECTTALKED:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
                
                WUConnectViewController  *connect=[[WUConnectViewController alloc]init];
                connect.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:connect animated:YES];
            }
            
            break;
        case MINEHEADERSELECTCOLLECTED:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"1"]) {
                
                WUStoreViewController  *store=[[WUStoreViewController alloc]init];
                store.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:store animated:YES];
                
            }
            
            break;
            
        case MINEHEADERSELECTHEADER:
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"userType"] isEqualToString:@"2"]) {
                
            } else {
                YHYDesigneViewsViewController  *Designe=[[YHYDesigneViewsViewController alloc]init];
                Designe.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:Designe animated:YES];
                
            }
            break;
            
        case MINEHEADERSELECTSCORE:
        {
            VippViewController *vipp=[[VippViewController alloc]init];
            vipp.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:vipp animated:YES];
        }
            break;
            
        case MINEHEADERSELECTREN :
        {
            VipViewController *vipView=[[VipViewController alloc]init];
            vipView.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vipView animated:YES];
        }
            
        default:
            break;
    }
}

#pragma mark -- footerView代理方法
- (void)footerPushViewController:(NSInteger)type {
    
    if (type == 1200) {
        
        VippViewController *vitality=[[VippViewController alloc]init];
        vitality.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vitality animated:YES];
    } else if (type == 1201) {
        
        SupeiViewController *supei=[[SupeiViewController alloc]init];
        supei.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:supei animated:YES];
    } else {
        
        VipViewController *vipView=[[VipViewController alloc]init];
        vipView.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vipView animated:YES];
    }
}


-(void) setAction
{
    SheeViewController *chong=[[SheeViewController alloc]init];
    [self.navigationController pushViewController:chong animated:YES];
}


-(void) shareAction
{
    WUShareSheet *sheet=[[WUShareSheet alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    sheet.delegate=self;
    sheet.backImageVi.image=[[self.view convertViewToImage]applyBlurWithRadius:10.0 tintColor:[UIColor colorWithWhite:1 alpha:0.4] saturationDeltaFactor:1.8 maskImage:nil];
}


-(void) shareButtonClick:(NSInteger)index
{
    if (index ==0) {
        
        NSLog(@"微信微信微信");
        
    }else if (index ==1){
        
        NSLog(@"微博微博微博");
        
    }else if (index ==2){
        NSLog(@"朋友圈朋友圈朋友圈");
    }else{
        NSLog(@"短信短信短信");
    }
}

@end
